package com.hmchat.model.entity;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;

import java.time.LocalDateTime;

/**
 * 用户实体类
 * 用于存储用户基本信息和认证相关数据
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Document(collection = "users")
public class User {

    @Id
    private String id;
    
    @Indexed(unique = true)
    private String username;
    
    @Indexed(unique = true)
    private String email;
    
    @Indexed(unique = true, sparse = true)
    private String phone;
    
    private String password;
    
    private String avatar;
    
    private LocalDateTime createdAt;
    
    private LocalDateTime updatedAt;
    
    private boolean enabled;
    
    private String[] roles;
    
    // 添加失败登录次数字段
    @Builder.Default
    private int failedAttempts = 0;
    
    // 添加最后登录时间
    private LocalDateTime lastLoginAt;
}